﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Revis.VClinicNet.Core.Domain
{
    public class Entry : IComparable<Entry>, IEquatable<Entry>
    {
        public virtual long Id { get; set; }
        public virtual Doctor Author { get; set; }
        public virtual Patient RelatedTo { get; protected set; }
        public virtual DateTime Date { get; protected set; }
        public virtual EntryContent Content { get; protected set; }

        #region Constructors

        public Entry()
        {
        }

        public Entry(Doctor author, Patient patient, DateTime date, EntryContent content) :
            this(0, author, patient, date, content)
        {

        }

        public Entry(long id, Doctor author, Patient patient, DateTime date, EntryContent content)
        {
            if (author == null) {
                throw new ArgumentNullException("Null author");
            }
            if (patient == null) {
                throw new ArgumentNullException("Null patient");
            }
            if (content == null) {
                throw new ArgumentNullException("Null content");
            }
            Author = author;
            RelatedTo = patient;
            Date = date;
            Content = content;
            Id = id;
        }

        #endregion

        #region Public Methods

        public virtual int CompareTo(Entry other)
        {
            return this.Date.CompareTo(other.Date);
        }

        public override bool Equals(object obj)
        {
            return Equals(obj as Entry);
        }

        public virtual bool Equals(Entry other)
        {
            if (other == null) {
                return false;
            }
            return this.Id == other.Id;
        }

        public override int GetHashCode()
        {
            return Id.GetHashCode() ^ base.GetHashCode();
        }

        #endregion


    }
}
